#include <pthread.h>  
#include <stdio.h>  
#include <unistd.h>  // 添加 sleep 所需头文件  

static int global = 1;  

void *t1_execute(void *arg) {  
    while (global < 100) {  
        printf("The value is %d\n", global);  
    }  
    return NULL;  // 显式返回，遵循线程函数规范  
}  

void *t2_execute(void *arg) {  
    while (1) {  
        global++;  
        sleep(1);  
    }  
    return NULL;  
}  

int main() {  // 修正 main 函数返回类型为 int  
    int i = 0;  
    pthread_t pid1, pid2;  
    int error1, error2;  

    error1 = pthread_create(&pid1, NULL, t1_execute, (void *)&i);  
    error2 = pthread_create(&pid2, NULL, t2_execute, (void *)&i);  

    if (error1 != 0 || error2 != 0) {  
        printf("pthread_create failed ");  
        return -1;  // 修正返回值  
    }  

    pthread_join(pid1, NULL);  
    pthread_join(pid2, NULL);  
    return 0;  
}  









